﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CaroLibraly;

namespace CaroRoomUI
{
    public partial class CaroRoomUI : UserControl
    {
        private Room _data = new Room();
        public Room Data
        {
            set
            {
                this._data = value;

                this.btnPlayer1.Text = this.FillName(this._data.Owner);
                this.btnPlayer2.Text = this._data.Rival == null ? "???" : this._data.Rival.Name;

                this.btnRoomName.Text = _data.Name;
                this.lblStatus.Text = this._data.Full ? "Đang chơi" : "Đang chờ...";
            }
            get
            {
                return this._data;
            }
        }

        private string FillName(Player pl)
        {
            string name = "";
            foreach (char c in pl.Name)
                name += c + "\n";
            return name;
        }

        public CaroRoomUI()
        {
            InitializeComponent();
            this._data = new Room();
        }

        public void SetRoom(Room r)
        {
            this.Data = r;
        }

        public void SetRival(Player _rival)
        {
            this.Data.SetRival(_rival);
            this.btnPlayer2.Text = _rival.Name;
            this.lblStatus.Text = "Đang chơi";
        }

        private void CaroRoomUI_MouseHover(object sender, EventArgs e)
        {
            this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
        }

        private void CaroRoomUI_MouseLeave(object sender, EventArgs e)
        {
            this.BorderStyle = System.Windows.Forms.BorderStyle.None;
        }
    }
}
